package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.QuotationProxy;
	import vn.demand.dragon.view.QuotationListMediator;
	import vn.demand.dragon.view.QuotationSearchMediator;
	import vn.demand.dragon.view.components.QuotationList;
	
	public class OpenQuotationListCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			if (facade.hasMediator(QuotationListMediator.NAME)) {
				TabManager.openTab(QuotationList, QuotationListMediator.NAME);
				return;
			}
			var ui:QuotationList = TabManager.openTab(QuotationList, QuotationListMediator.NAME) as QuotationList;
            facade.registerProxy(new QuotationProxy(QuotationProxy.NAME, null));
            var quotationProxy:QuotationProxy  = facade.retrieveProxy(QuotationProxy.NAME) as QuotationProxy;
            quotationProxy.loadQuotations();
            
            facade.registerMediator(new QuotationListMediator(ui));
            facade.registerMediator(new QuotationSearchMediator(QuotationSearchMediator.NAME, ui.searchForm));
        }
	}
}